package com.noble.glamour.module.local.msgview.chatview.msgpanel;

import android.content.Context;
import android.widget.TextView;
import com.noble.glamour.R;
import com.noble.glamour.bean.center.user.light.UserLight;
import com.noble.glamour.module.local.chat.msgtype.bean.BaseMessage;
import com.noble.glamour.module.local.chat.msgtype.BaseMessageType;
import com.noble.glamour.module.local.chat.msgtype.type.TextMessage;
import com.noble.glamour.module.local.msgview.ChatAdapter;
import com.noble.glamour.module.local.msgview.chatview.ChatPanel;
import com.noble.glamour.module.logic.application.App;
import com.noble.glamour.ui.utils.MyURLSpan;

/**
 * 文字及html文字类型消息展示panel
 * Created by Kind on 2017/5/12.
 */
public class ChatPanelText extends ChatPanel {

    private TextView chat_item_text;

    public ChatPanelText(Context context, ChatAdapter.ChatInstance chatInstance, boolean sender) {
        super(context, chatInstance, R.layout.f1_chat_item_panel_text, sender);
    }

    @Override
    public void initView() {
        chat_item_text = (TextView) findViewById(R.id.chat_item_text);
    }

    @Override
    public boolean reset(BaseMessage msgData, UserLight infoLightweight) {
        if (msgData == null || !(msgData instanceof TextMessage)) return false;
        TextMessage msg = (TextMessage) msgData;
        String str;
        if(msg.getType() == BaseMessageType.htmlText.getMsgType()
                || msg.getType() == BaseMessageType.autoUpdateHtml.getMsgType()){
            str = msg.getHtm();
        }else {
            str = msg.getMsgDesc();
        }

        MyURLSpan.addClickToTextViewLink(App.getActivity(), chat_item_text, str);
        return true;
    }
}
